<%@page import="entity.Address"%>
<%@page import="dao.AddressDao"%>
<%@page import="java.util.List"%>
<%@page import="dao.BookDao"%>
<%@page import="entity.Book"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Iterator"%>
<%@page import="service.FindCart"%>
<%@page import="java.util.HashMap"%>
<%@page import="entity.Member"%>
<%@page import="dao.MemberDao"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page errorPage="error.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" charset="utf-8" />
        <style>
            p{
                display: block;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                width: 70%;
                }
                 a{
                    text-decoration:none;  
                }
            .shanglue{
        overflow: hidden; 
        white-space:nowrap;
        display:block;
        text-overflow: ellipsis;
    }
  div{border-radius: 10px; }
        </style>
    </head>
    <body style=" background-color: whitesmoke">
        <div style=" width:1670px; height: 200px;">
        <div style="float: left;"><a href="index"><img src="img/充值2.jpg" width="180px" height="180px"></a></div>
        <div style=" margin-top:80px;font-size: 20px; float: right"><a href="Cart.jsp" style="color: thistle; font-weight: bold; font-size:35px;">购物车</a><img src="img/购物车2.jpg" width="60px" height="60px"></div>
        </div>
        <div style="margin-left: 10px;width:1200px; margin-top: 0px;">
            <h1 style="margin-left:50%;font-size:60px; float: left; margin-top:0px; font-weight:bold;">确认订单</h1>
            <br>
            <div style="float:left; border:1px darkgray solid; width: 90%; margin-left:20%; background-color: #e4b9c0">
            <%
                Member member=new MemberDao().getMemberByName((String)session.getAttribute("username"));
                HashMap<Integer,Integer> map=new FindCart().findAllCart(member.getId());

                float price=0;

                Iterator it = map.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry entry = (Map.Entry) it.next();
                    Integer bookId = (Integer)entry.getKey();
                    Integer count = (Integer)entry.getValue();


                Book book=new BookDao().getBookById(bookId);

            %>

                <div style="float:left;margin:10px 15px;width:230px; height: 520px;border: 1px bisque solid; background-color: blanchedalmond;border-radius: 20px;">
                    <p style="font-size: 20px;width:220px"><%=book.getBookName()%></p>
                    <div style=" width: 220px; height: 300px;">
                        <img src="img/<%=book.getCover()%>" style="border-radius: 10px" width="220px" height="300px" alt="<%=book.getBookName()%>">
                    </div>
                    <div >
                        编号：<%=book.getId()%><br>
                        作者：<%=book.getAuthor()%><br>
                        数量：<%=count%>
                        <p>单价：<span id="price"><%=book.getPrice()%></span>   </p>                
                        <a href="gbbi?id=<%=book.getId()%>" target="blank">详情</a>
                    </div>
                </div>

                    <%
                        price+=count*book.getPrice();
                        }
                    %>
            </div>
                    <div style="clear: both ;margin-left:20%">
                        <h1 style="color: tomato">实付款：<%=price%>元</h1>
                            <form action="bas" method="post" onsubmit="return check()">
                            <h3>选择收货地址：</h3><br>
                            <%

                                List<Address> list=new AddressDao().getAllUndeletedAddress(member.getId());
                                for(int i=0;i<list.size();i++){
                            %>
                            <div style=" border:1px cadetblue solid; width: 230px; height: 150px; float: left; margin-left:10px; margin-top: 0px;border-radius: 10px; background-color: white;">
                            <input type="radio" name="address" value="<%=list.get(i).getId()%>" checked="checked">
                            <div>
                                <span class="shanglue">详细地址：<%=list.get(i).getAddress()%></span><br>
                                &nbsp;&nbsp;收件人：<%=list.get(i).getAddressee()%><br>
                                &nbsp;&nbsp;电话：<%=list.get(i).getPhone()%><br>
                                &nbsp;&nbsp;邮编：<%=list.get(i).getZipcode()%>
                            </div>
                            </div>
                            
                            <%
                                }
                            %>
                            <br><br><br><br><br><br><br><br><br><br>
                            <button style="width: 80px; height: 45px; font-size:20px;" class="btn btn-success">支付</button>
                        </form>
                    </div>
                <script type="text/javascript">
                function check(){
                    var b=<%=list.size()%>;
                    if(b===0){
                        alert("您还未添加收货地址！");
                        return false;
                    }

                    return true;

                }
            </script>
        </div><br><br><br><br><br>
    </body>
</html>